//
// Copyright (c) 2009 All Right Reserved
//
// Stephen Toub
// stoub@microsoft.com
// 2009-01-01
// Contains ...
namespace LargoCommon.Midi
{
using System;
using System.Globalization;
using System.IO;
using System.Text;
using Music;
/// Midi event to play a note.
[Serializable]
public sealed class VoiceNoteOn : VoiceAbstractNote {
#region Fields
/// The category status byte for VoiceNoteOn messages.
private const byte CategoryStatusByte = 0x9;
/// The velocity of the note (0x0 to 0x7F).
private byte velocity;
#endregion
#region Constructors
/// Initializes a new instance of the VoiceNoteOn class.
/// The amount of time before this event.
/// The channel (0x0 through 0xF) for this voice event.
/// The MIDI note to sound (0x0 to 0x7F).
/// The velocity of the note (0x0 to 0x7F).
public VoiceNoteOn(long deltaTime, MidiChannel channel, byte note, byte velocity) :
base(deltaTime, CategoryStatusByte, channel, note) {
this.Velocity = velocity;
}
#endregion
#region Properties
/// Gets the velocity of the note (0x0 to 0x7F).
/// General musical property.
public byte Velocity {
get => this.velocity;
private set {
if (value > 127) {
this.velocity = 127;
//// throw new ArgumentOutOfRangeException("value", value, "The velocity must be in the range from 0 to 127.");
}
this.velocity = value;
}
}
/// Gets The second parameter as sent in the MIDI message.
/// General musical property.
public override byte Parameter2 => this.velocity;
#endregion
#region Static Methods
#endregion
#region To String
/// Generate a string representation of the event.
/// A string representation of the event.
public override string ToString() {
var sb = new StringBuilder();
sb.Append(base.ToString());
sb.Append("\t");
sb.Append(" v=");
sb.Append(this.velocity.ToString(CultureInfo.CurrentCulture.NumberFormat)); //// ToString("X2"
return sb.ToString();
}
#endregion
#region Methods
/// Write the event to the output stream.
/// The stream to which the event should be written.
public override void Write(Stream outputStream) {
if (outputStream == null) {
return;
}
//// Write out the base event information
base.Write(outputStream);
//// Write out the data
outputStream.WriteByte(this.velocity);
}
#endregion
}
}